import { Form, message, } from "antd"
import HomePage_ModalComponent_HeaderNormalComponent from "../../../../../../component/modal/component/headerNormal"
import lessModule from "./index.module.less"
import HomePage_ModalComponent_NormalFooterComponent from "../../../../../../component/modal/component/normalFooter"
import { $EventBus_off, $EventBus_on } from "../../../../../../../../common/utils"
import { useEffect, useState } from "react"

import HomePage_ModalComponent_NormalFormComponent from "../../../../../../component/modal/component/normalForm"
import { $Http } from "../../../../../../../../network"

// 主页-数据维护页面-隔直维护页面-弹窗组件
interface homePageDataMaintenancePageUprightMaintenancePageModalComponentComponentInterface {
    isReview?: boolean
    sourceData: object
    change_cancel: Function
}
const HomePage_DataMaintenancePage_UprightMaintenancePage_ModalComponent: React.FC<homePageDataMaintenancePageUprightMaintenancePageModalComponentComponentInterface> = (props) => {
    const [form] = Form.useForm()
    const [mainOptionList, setMainOptionList] = useState<Array<object>>([])
    const [connectMethodList, setConnectMethodOptionList] = useState<Array<object>>([])
    const formItemList = [
        {
            label: "安装站点",
            key: "stationName",
            type: "singleBtn",
            monitoringType: "站点",
            monitorModalName: "请选择安装站点",
            placeholder: "请选择安装站点",
            isRequire: true,
        },
        {
            key: "stationID",
            hide: true
        },
        {
            label: "巡维中心",
            key: "maintainCentre",
            type: "input",
            placeholder: "请选择安装站点",
            isDisabled: true
        },
        {
            label: "电压等级",
            key: "volLevel",
            type: "input",
            placeholder: "请选择安装站点",
            isDisabled: true
        },
        {
            label: "安装主变",
            key: "monitorMain",
            type: "multipleSelect",
            placeholder: "请选择",
            optionList: mainOptionList,
            isRequire: true,
        },
        {
            label: "调度编号",
            key: "dispatchNumber",
            type: "input",
            placeholder: "请输入",
            isRequire: true
        },
        {
            label: "装置厂家",
            key: "deviceFac",
            type: "input",
            placeholder: "请输入",
            isRequire: true
        },
        {
            label: "装置型号",
            key: "deviceModel",
            type: "input",
            placeholder: "请输入",
            isRequire: true
        },
        {
            label: "出厂编号",
            key: "facNumber",
            type: "input",
            placeholder: "请输入",
            isRequire: true
        },
        {
            label: "投运日期",
            key: "opeDate",
            type: "datePicker",
        },
        {
            label: "IP地址",
            key: "ipAddress",
            type: "input",
            placeholder: "请输入",
        },
        {
            label: "接线方式",
            key: "connectMethod",
            type: "select",
            placeholder: "请选择",
            optionList: connectMethodList,
            isRequire: true
        },
        {
            type: "svg",
            width: "100%"
        },
        {
            label: "备注",
            key: "notes",
            type: "textArea",
            placeholder: "请输入",
            row: 3,
            width: "100%"
        },
        {
            HomePage_ModalComponent_NormalFormComponent: "参数配置",
            smallTitle: "隔直电容",
            type: "title",
            width: "100%"
        },
        {
            label: "额定电压",
            key: "capacitorVol",
            type: "input",
            placeholder: "请输入",
        },
        {
            label: "总电容量",
            key: "capacitorTotal",
            type: "input",
            placeholder: "请输入",
        },
        {
            label: "容抗",
            key: "condensance",
            type: "input",
            placeholder: "请输入",
        },
        {
            label: "短时耐受电流",
            key: "withstandCur",
            type: "input",
            placeholder: "请输入",
        },
        {
            label: "耐受时间",
            key: "withstandTime",
            type: "input",
            placeholder: "请输入",
        },
        {
            smallTitle: "快速旁路开关单元",
            type: "title",
            width: "100%"
        },
        {
            label: "额定电压",
            key: "unitVol",
            type: "input",
            placeholder: "请输入",
        },
        {
            label: "总电容量",
            key: "unitCapacity",
            type: "input",
            placeholder: "请输入",
        },
        {
            smallTitle: "CT单元",
            type: "title",
            width: "100%"
        },
        {
            label: "直流CT",
            key: "ctDirect",
            type: "input",
            placeholder: "请输入",
        },
        {
            label: "交流CT变比",
            key: "ctAcRatio",
            type: "input",
            placeholder: "请输入",
        },
        {
            label: "热稳定",
            key: "thermalStability",
            type: "input",
            placeholder: "请输入",
        },
        {
            label: "动稳定",
            key: "dynamicStability",
            type: "input",
            placeholder: "请输入",
        },
    ]

    // 广播函数数据
    const eventBusFuncData = {
        // 提交操作
        submitOperation: (data: object) => {
            form.validateFields().then((data: object) => {

                props.sourceData["type"] === "see" ? props.change_cancel() : $Http(props.sourceData["type"] === "add" ? "create" : "edit", { typeName: "数据维护/隔直维护", ...data, ...(props.sourceData["type"] === "edit" && { id: props.sourceData["id"] }) }).then((res) => {
                    message.success(res["success"])
                    props.change_cancel()
                })
            })
        }

    }

    useEffect(() => {
        $EventBus_on(eventBusFuncData)
        return () => {
            $EventBus_off(eventBusFuncData)
        }
    }, [])

    return (
        <div className={lessModule["homePageDataMaintenancePageUprightMaintenancePageModalComponentComponent"]}>
            {
                !props.isReview && <HomePage_ModalComponent_HeaderNormalComponent name={props.sourceData["type"] === "add" ? "新增隔直装置" : props.sourceData["type"] === "edit" ? "编辑隔直装置" : props.sourceData["type"] === "see" ? "隔直详情" : ""} padding="15px 24px" change_cancel={props.change_cancel} />
            }
            <main className={lessModule["homePageDataMaintenancePageUprightMaintenancePageModalComponentComponent-main"]}>
                <div className={lessModule["homePageDataMaintenancePageUprightMaintenancePageModalComponentComponent-main__title"]}>基本信息</div>
                <HomePage_ModalComponent_NormalFormComponent form={form} type={props.sourceData["type"]} formItemList={formItemList} sourceData={props.sourceData} change_mainOptionList={setMainOptionList} change_connectMethodOptionList={setConnectMethodOptionList} />
            </main>
            {
                !props.isReview && <HomePage_ModalComponent_NormalFooterComponent change_cancel={props.change_cancel} />
            }
        </div>
    )
}

export default HomePage_DataMaintenancePage_UprightMaintenancePage_ModalComponent